//
//  zhuanBiViewController.m
//  shopping
//
//  Created by 马田成 on 2017/9/23.
//  Copyright © 2017年 qianyi. All rights reserved.
//

#import "zhuanBiViewController.h"
#import "BindingAcountViewController.h"
#import "JieChuBangDingViewController.h"
#import "aaaaaaaaaaaaaViewController.h"
@interface zhuanBiViewController ()
@property (weak, nonatomic) IBOutlet UITextField *numTF;
@property (weak, nonatomic) IBOutlet UITextField *yzmTF;

@end

@implementation zhuanBiViewController
- (void)viewWillAppear:(BOOL)animated{
    
    
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:NO];
    
    //绑定账号
    
    NSMutableDictionary *productParams=[[NSMutableDictionary alloc]init];
    NSString *token = [PublicFunction getConfigWithKey:@"token"];
    // NSString *token = @"32728a411b83e29b9836262a72477e3e0dac";
    
    [productParams setValue:token forKey:@"token"];
    [[MNetworkHandler sharedInstance]conURL:adminUserJudgeBindAccount networkType:NetWorkPOST params:productParams delegate:nil showHUD:NO successBlock:^(id returnData) {
        
        if ([[returnData objectForKey:@"code"]intValue]==1) {
            
           
            [PublicFunction showAlert:nil message:@"已绑定账号" duration:5.0f];
            
        }else {
            
         
            [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];
            
        }
        
    } failureBlock:^(NSError *error) {
        
        NSLog(@"%@",error);
        
//        [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
        
    }];

    
    
    
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setTitle:@"转资产包"];
    UIButton *buttonAdd = [[UIButton alloc] init];
    
    buttonAdd.frame = CGRectMake(DEF_SCREEN_WIDTH - 15, 0, 80, 40);
    [buttonAdd setTitle:@"绑定账号" forState:UIControlStateNormal];
    [buttonAdd addTarget:self action:@selector(registerClick) forControlEvents:UIControlEventTouchUpInside];
    UIColor * color = getColor(@"222222");
    [buttonAdd setTitleColor:color forState:UIControlStateNormal];
    buttonAdd.titleLabel.font = [UIFont systemFontOfSize:15];
    UIBarButtonItem *rightItme = [[UIBarButtonItem alloc]initWithCustomView:buttonAdd];
    self.navigationItem.rightBarButtonItem = rightItme;
    // Do any additional setup after loading the view from its nib.
}
- (void)registerClick{

    //绑定账号
    
    NSMutableDictionary *productParams=[[NSMutableDictionary alloc]init];
    NSString *token = [PublicFunction getConfigWithKey:@"token"];
    // NSString *token = @"32728a411b83e29b9836262a72477e3e0dac";
    
    [productParams setValue:token forKey:@"token"];
    [[MNetworkHandler sharedInstance]conURL:adminUserJudgeBindAccount networkType:NetWorkPOST params:productParams delegate:nil showHUD:NO successBlock:^(id returnData) {
        
        if ([[returnData objectForKey:@"code"]intValue]==1) {
            
            JieChuBangDingViewController *vc = [[JieChuBangDingViewController alloc] init];
            
            vc.hidesBottomBarWhenPushed = YES;
            NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
            dic = [returnData objectForKey:@"data"];
            vc.nameStr = [dic objectForKey:@"name"];
            [self.navigationController pushViewController:vc animated:YES];
            
        }else {
            
            BindingAcountViewController * modifier = [[BindingAcountViewController alloc] init];
            
            modifier.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:modifier animated:YES];
            
        }
        
    } failureBlock:^(NSError *error) {
        
        NSLog(@"%@",error);
        
//        [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
        
    }];


    
}
- (IBAction)faSongYZM:(UIButton *)sender {
    
    NSMutableDictionary *productParams=[[NSMutableDictionary alloc]init];
    NSString *token = [PublicFunction getConfigWithKey:@"token"];
    // NSString *token = @"32728a411b83e29b9836262a72477e3e0dac";
    
    [productParams setValue:token forKey:@"token"];
    [[MNetworkHandler sharedInstance]conURL:adminUserSendCode networkType:NetWorkPOST params:productParams delegate:nil showHUD:NO successBlock:^(id returnData) {
        
        if ([[returnData objectForKey:@"code"]intValue]==1) {
            
            
            [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];
            
            
        }
        
        else {
            
            [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];
            
        }
        
    } failureBlock:^(NSError *error) {
        
        NSLog(@"%@",error);
        
//        [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
        
    }];
    
    
}
- (IBAction)queDing:(UIButton *)sender {
    
    NSMutableDictionary *productParams=[[NSMutableDictionary alloc]init];
    NSString *token = [PublicFunction getConfigWithKey:@"token"];
    // NSString *token = @"32728a411b83e29b9836262a72477e3e0dac";
    
    [productParams setValue:token forKey:@"token"];
    [productParams setValue:self.yzmTF.text forKey:@"code"];
    [productParams setValue:self.numTF.text forKey:@"num"];
    [[MNetworkHandler sharedInstance]conURL:adminUserTradeMoneyTransfer networkType:NetWorkPOST params:productParams delegate:nil showHUD:NO successBlock:^(id returnData) {
        
        if ([[returnData objectForKey:@"code"]intValue]==1) {
            
            aaaaaaaaaaaaaViewController * vc = [[aaaaaaaaaaaaaViewController alloc] init];
            vc.type = @"2";
            [self.navigationController pushViewController:vc animated:YES];
            

            
        }
        
        else {
            
            [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];
            
        }
        
    } failureBlock:^(NSError *error) {
        
        NSLog(@"%@",error);
        
//        [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
        
    }];

    
    
    
}
//跳转到国数联盟

- (IBAction)tiaoZhuanClick:(UIButton *)sender {
    
    NSString *username = @"gslm";
    [self openUserPage:username];
    
    
    
}
- (BOOL)isInstagramInstalled {
    NSURL *instagramURL = [NSURL URLWithString:@"gslm://location?id=1"];
    return [[UIApplication sharedApplication] canOpenURL:instagramURL];
}

- (void)openUserPage:(NSString *)username {
    NSURL *fansPageURL;
    if ([self isInstagramInstalled]) {
        fansPageURL = [NSURL URLWithString:[NSString stringWithFormat:@"gslm://user?username=%@", username]];
    } else {
        fansPageURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://instagram.com/%@", username]];
    }
    [[UIApplication sharedApplication] openURL:fansPageURL];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
